<div id='map'>
  <el-breadcrumb class='bread' separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!-- 查询 -->
  <el-row :gutter="20">
    <el-col :span="8">
      <el-input placeholder="请输入内容" v-model="searchText">
        <!-- slot="append" 决定 搜索图标的前后位置的 append:后  prepend :前面 -->
        <el-button
          @click="startQuery"
          slot="append"
          icon="el-icon-search"
        ></el-button>
      </el-input>
    </el-col>
    <el-col :span="3">
      <el-button @click="showAddUserDialog">添加用户</el-button>
    </el-col>
  </el-row>

  <!--
    table : 表格
      :data 绑定数据  (数组)

    table-column : 表格列
       prop : 属性赋值
       label  :标签名

     因为 tableData 是四个元素的数组,所以会把里面的内容都会创建四份

   -->
  <el-table :data="userList" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180">
    </el-table-column>
    <el-table-column prop="email" label="邮箱" width="180"> </el-table-column>
    <el-table-column prop="mobile" label="电话"> </el-table-column>
    <el-table-column prop="type" label="用户状态">
      <!-- 插槽 -->
      <!-- scope 作用域 包含当前行里的一些信息 scope.row 当前行所对应的数据对象 -->
      <template slot-scope="scope">
        <el-switch
          @change="switchChangeState(scope.row)"
          v-model="scope.row.mg_state"
        >
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column prop="type" label="操作">
      <!-- 自定义列 里面要放一个 template  -->
      <!-- plain : 镂空 -->
      <!-- size : mini  最小的 -->
      <!-- circle : 圆形 -->
      <!-- √  是 图标  -->
      <template slot-scope="scope">
        <el-button
          @click="showEditDialig(scope.row)"
          plain
          size="mini"
          type="primary"
          icon="el-icon-edit"
        ></el-button>
        <el-button
          @click="delUser(scope.row.id)"
          plain
          size="mini"
          type="danger"
          icon="el-icon-delete"
        ></el-button>
        <el-button plain size="mini" type="success"
          ><i class="el-icon-check"></i> 分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <el-pagination
    @current-change="curPageChange"
    background
    layout="prev, pager, next"
    :total="total"
    :page-size="2"
    :current-page="currentPage"
  >
  </el-pagination>

  <!-- 添加用户 对话框 -->
  <!--
     el-dialog : 对话框
        title : 对话框的标题
        :visible.sync="dialogFormVisible"  空值对话框的显示与隐藏

   -->
  <el-dialog title="添加用户" :visible.sync="dialogAddUserFormVisible">
    <el-form
      ref="addUserForm"
      :model="addUserForm"
      label-width="100px"
      :rules="rules"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addUserForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addUserForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="addUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input v-model="addUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAddUserFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 编辑用户的对话框 -->
  <el-dialog title="编辑用户" :visible.sync="dialogEditUserVisible">
    <el-form :model="editUsersForm" label-width="100px">
      <el-form-item label="用户名">
        <!-- <el-input v-model="editForm.username" autocomplete="off"></el-input>
         -->
        <el-tag type="info">{{ editUsersForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="editUsersForm.email" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机">
        <el-input v-model="editUsersForm.mobile" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogEditUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="updateUser">确 定</el-button>
    </div>
  </el-dialog>
</div>
